#!/bin/sh
if [ -z "$S" ] ; then
	echo 'S not set, did you source config?'
	exit 1
fi

pkg=$1
sec=$2
if [ -z "$pkg" ] || [ -z "$sec" ] ; then
	echo 'this script prints the specified section of the specified package.'
	echo 'need package name as argv 1 and section name as argv 2!'
	exit 1
fi

fl=$S/pkg/$pkg
if [ ! -e "$fl" ] ; then
	echo "package $fl does not exist!"
	exit 1
fi

in_sec=0
while read n ; do
	test "x$n" = "x["${sec}"]" && { in_sec=1 ; continue ; }
	if [ "$in_sec" = 1 ] ; then
		[ "$sec" != build ] && printf "%s" "$n" | grep "^\[" >/dev/null \
		&& break
		[ "$sec" != build ] \
		&& test "x$n" = x && break
#		[ "$sec" != build ] \
#		&& [ $(printf "%s" "$n" | wc -c) = 0 ] && break
		printf "%s\n" "$n"
	fi
done < "$fl"

exit 0
